person_info = {
    "name": "Alex",
    "age": 30,
    "country": "USA",
    "language": ["English", "Spanish"],
    "is_student": False
}
print(person_info.get("name"))
person_info["age"]=31
print(person_info)
person_info["height"]=175
print(person_info)
del person_info["is_student"]
print(person_info)
for e in person_info.items():
    print(e)
for x in person_info.keys():
    print(x,end=(' '))
for d in person_info.values():
    print(d,end=' ')

person_info['email']="alex@example.com"
print(person_info)
person_info["language"]='English'
print(person_info)
info_l=len(person_info["language"])
print(info_l)
# 添加一种新语言9\10
#erson_info['language'].append('German')
print(person_info)  # 输出: {'name': 'Alice', 'languages': ['English', 'Spanish', 'German']}
person_info1=list(person_info["language"])
person_info1.append("Frenc  h")
print(person_info1)
#进阶

# 初始化员工信息字典
employees = {
    101: {
        "name": "Alice",
        "age": 30,
        "gender": "Female",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [70000, 80000, 90000]
    }
}

# 1. 新增一个员工的信息到 employees 字典中
new_employee = {
    102: {
        "name": "Bob",
        "age": 28,
        "gender": "Male",
        "position": "Software Engineer",
        "team": "Development",
        "salary_history": [65000, 75000]
    }
}
employees.update(new_employee)

# 2. 删除一个指定的员工的信息
employee_id_to_delete = 102
if employee_id_to_delete in employees:
    del employees[employee_id_to_delete]

# 3. 更新员工 101 的年龄至 31
employees[101]["age"] = 31

# 4. 增加员工 101 薪资历史中的最新薪资至 95000
employees[101]["salary_history"].append(95000)

# 5. 计算员工 101 的平均薪资
average_salary = sum(employees[101]["salary_history"]) / len(employees[101]["salary_history"])
print(f"员工 101 的平均薪资是: {average_salary}")

# 6. 找出所有年龄大于 25 岁的员工的姓名和 ID
employees_over_25 = [(emp_id, emp_info["name"]) for emp_id, emp_info in employees.items() if emp_info["age"] > 25]
print("年龄大于 25 岁的员工的姓名和 ID:", employees_over_25)

# 7. 对 employees 中的每个员工，添加 'bonus' 键至其字典中，其中值是最新薪资的 10%
for emp_info in employees.values():
    latest_salary = emp_info["salary_history"][-1]
    emp_info["bonus"] = latest_salary * 0.1

# 8. 将员工 101 的职位更新为 "Senior Data Scientist"
employees[101]["position"] = "Senior Data Scientist"

# 9. 从员工的信息中移除 gender 键
for emp_info in employees.values():
    if "gender" in emp_info:
        del emp_info["gender"]

# 10. 创建一个新的嵌套字典，该字典仅包含员工的 name 和 position
new_dict = {emp_id: {"name": emp_info["name"], "position": emp_info["position"]} for emp_id, emp_info in employees.items()}
print("仅包含员工 name 和 position 的新嵌套字典:", new_dict)
